Skip to content

Add remaining Genslip parameters to SRFConfig#93

Open
Copilot wants to merge 9 commits intopegasusfrom
copilot/add-genslip-parameters
Open

Add remaining Genslip parameters to SRFConfig#93
Copilot wants to merge 9 commits intopegasusfrom
copilot/add-genslip-parameters

Conversation

Copy link

Copilot AI commented Mar 2, 2026

The codebase exposed only a small subset of genslip v5.6.2 parameters. This adds the full parameter set with correct defaults extracted from the genslip source.

Changes

  • defaults.yaml: ~90 new parameters added under srf:, grouped by category (rise time, hybrid correlation length, rupture velocity, tapering, time shift factors, kinematic models, roughness/wavelength, miscellaneous, aseismic). rvfrac_slip_sig added to rupture_velocity section.
  • schemas.py: SRF_SCHEMA extended with validators for all new fields. Added KModel IntEnum for kinematic model index. rvfrac_slip_sig moved to RUPTURE_VELOCITY_SCHEMA. Fields deferred to future CLI arguments (roughnessfile, init_slip_file, read_slip_file) excluded.
  • realisations.py: SRFConfig dataclass extended with typed fields. kmodel/hyb_corlen_kmodel use the KModel enum; kord is int. rvfrac_slip_sig moved to RuptureVelocity.
  • realisation_to_srf.py: _build_genslip_command handles Enum values by serialising to their integer value.
  • Tests: test_srf_config_example and test_build_genslip_command_static_args updated to cover all new fields with correct types.

Design decisions

Genslip type Python type Notes
0/1 flags bool Serialised as 0/1 in command
-1, -999, 1e15 sentinels None Skipped by _build_genslip_command
Kinematic model index (kmodel, hyb_corlen_kmodel) KModel (IntEnum) Serialised as integer value
Filter order (kord) int Validated with And(int, _is_positive)
Optional file paths str | None Skipped when None
Rupture velocity slip sigma (rvfrac_slip_sig) float | None in RuptureVelocity Moved from SRFConfig for future HF sync
Original prompt

This section details on the original issue you should resolve

<issue_title>Add remaining Genslip parameters into the codebase</issue_title>
<issue_description>Currently we expose a limited subset of genslip parameters in the code base, but we could do to add the rest. Here are the default values in YAML format that I have extracted from genslip_v5.6.2.c:

# Rise time and source time function values
beta_asp: 0.3
beta_deep: 0.13
beta_mid: 0.13
beta_mid_depth: 6.5
beta_mid_depth_range: 1.5
beta_shal: 0.5
beta_shal_depth: 2.0
beta_shal_depth_range: 1.0
beta_subevt: 0.1
deep_risetimedep: 17.5
deep_risetimedep_range: 2.5
deep_risetimefac: 2.0
risetime_coef: 1.6
risetimedep: DEFAULT_DEPTH_SCALING_LEVEL
risetimedep_range: DEFAULT_DEPTH_SCALING_RANGE
risetimefac: 2.0
rt_rand: 0.0
rt_scalefac: DEFAULT_RT_SCALEFAC
stype: null

# Hybrid Correlation Length (hyb_corlen) Parameters
hyb_corlen_deep_wt_end: 1.0
hyb_corlen_deep_wt_start: 0.0
hyb_corlen_dep: DEFAULT_DEPTH_SCALING_LEVEL
hyb_corlen_dep_range: DEFAULT_DEPTH_SCALING_RANGE
hyb_corlen_fac: 2.0
hyb_corlen_flag: 0
hyb_corlen_kmodel: 5
hyb_corlen_shal_wt_end: 0.0
hyb_corlen_shal_wt_start: 1.0
hyb_corlen_side_taper: 0.08

# Rupture Velocity & Fault Dimensions
fdrup_scale_slip: 0
fdrup_time: 0
rupture_delay: 0.0
rvfmax: 1.414
rvfmin: 0.25
rvfrac_slip_sig: -1.0

# Tapering & Slip Level Adjustments
truncate_zero_slip: DEFAULT_TRUNCATE_ZERO_SLIP
slip_water_level: -1.0
slip_sigma: DEFAULT_SLIP_SIGMA
rake_sigma: 15.0
fractal_rake: 0

# Time Shift Factors (tsfac)
tsfac1_scor: 0.8
tsfac1_sigma: 1.0
tsfac2_lambda_max: 5.0
tsfac2_lambda_min: -1.0
tsfac2_scor: 0.5
tsfac2_sigma: 1.0
tsfac_bzero: -0.1
tsfac_coef: 1.1
tsfac_main: -1.0e+15
tsfac_slope: -0.5

# Kinematic Models & Corner Frequencies
circular_average: DEFAULT_CIRCULAR_AVERAGE
kmodel: MAI_FLAG
kord: 4
kx_corner: null
ky_corner: null
magC: 6.3
mag_area_Acoef: -1.0
mag_area_Bcoef: -1.0
mai_wt: 0.5
modified_corners: DEFAULT_MODIFIED_CORNERS
somerville_wt: 0.5
stretch_kcorner: DEFAULT_STRETCH_KCORNER
use_gaus: 1
use_median_mag: 0
xmag_exponent: 0.5
ymag_exponent: 0.5

# Roughness & Wavelength Limits
alpha_rough: -1.0
lambda_max: -1.0
lambda_min: -1.0
roughnessfile: null
wavelength_max: 1.0e+15
wavelength_min: -1.0

# Miscellaneous Slip/Rupture/Rake Vars
asp_taper_fac: 0.05
extend_fac: -1.0
flen_max: -1.0
fwid_max: -1.0
init_slip_file: null
moment_fraction: -1.0
perturb_subfault_location: 1
rand_rake_degs: DEFAULT_RAND_RAKE_DEGS
read_slip_file: 0
rtime1_depth: 2.0
rtime1_depth_range: 1.0
rtime1_scor: 0.8
rtime1_sigma: DEFAULT_SLIP_SIGMA
rtime2_scor: 0.5
rtime2slip_exp: 0.5
rtime_rand: -1.0
set_rake: -999.0
svr_wt: 0
target_savg: -1.0
use_Mw: 1

# Aseismic & Segment Settings
aseis_flag: 0
aseis_smooth: 0
aseis_dep: 10.0
aseis_fac: -1.0
xshift: 0.0
yshift: 0.0

The tasks to complete this feature would be as follows:

  1. Add this YAML block into the root defaults.yaml file: here.
  2. Update the schema in schemas.py: here.
  3. Check that genslip is correctly supplied with these values by running realisation-to-srf with an input realisation. You could probably steal one from Cesar or Ayushi and update it using the migration tool on your new branch. The genslip command is built automatically from the realisation config in _build_genslip_command.
  4. Update the test cases in tests/test_realisation_to_srf.py and tests/test_realisation.py to include these new defaults.
    </issue_description>

<agent_instructions>You may use these defaults for named constants
#define DEFAULT_DHYPO_FRAC 0.75 /* hypo at 0.75 down-dip width /
#define DEFAULT_SHYPO_STEP 20.0 /
hypo spacing at 20 km along strike /
#define DEFAULT_SHYPO_MIN_OFF 1.0 /
hypos start at 1.0 km along strike /
#define DEFAULT_SLIPS_TO_HYPOS 2 /
#slip models = 2 times #hypos */

#define DEFAULT_DT 0.1
#define NTMAX 10000
#define SOMERVILLE_FLAG 1
#define MAI_FLAG 2
#define INPUT_CORNERS_FLAG -1
#define MINSLIP 1.0e-02

#define DEFAULT_KMODEL 2
#define DEFAULT_FLIP_AT_SURFACE 1
#define DEFAULT_STRETCH_KCORNER 0
#define DEFAULT_CIRCULAR_AVERAGE 0
#define DEFAULT_MODIFIED_CORNERS 0
#define DEFAULT_TRUNCATE_ZERO_SLIP 1
#define DEFAULT_RAND_RAKE_DEGS 60.0
#define DEFAULT_SLIP_SIGMA 0.85

#define DEFAULT_TSFAC -0.5
#define DEFAULT_TSFAC_COEF 1.8
#define DEFAULT_TSFAC_FACTOR 1

#define DEFAULT_RT_SCALEFAC 1

#define DEFAULT_VR_TO_VS_FRAC 0.8 /* vrup = 0.8 times local Vs /
#define DEFAULT_SHAL_VRUP_FRAC 0.7 /
shallow_vrup...


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…tests

Co-authored-by: lispandfound <12835929+lispandfound@users.noreply.github.com>
Copilot AI changed the title [WIP] Add remaining Genslip parameters into the codebase Add remaining Genslip parameters to SRFConfig Mar 2, 2026
@lispandfound lispandfound self-requested a review March 2, 2026 21:51
@lispandfound
Copy link
Contributor

Testing Instructions

To test that your defaults are validated by your schema:

  1. Install the "test" optional dependencies,
  2. Run pytest tests/test_realisation.py::test_defaults_are_loadable.

There are a couple of tests that use the SRFConfig block, the relevant tests are test_realisation_to_srf.py and test_realisation.py::test_srf_config_example.

Comment on lines +724 to +727
Literal(
"roughnessfile",
description="Path to roughness file (null = no file).",
): Or(str, None),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this, it should be passed as a command line argument (at a later date). Make sure it is removed from the tests and yaml defaults as well.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed roughnessfile from schemas, realisations, defaults, and tests in commit 5401095. Also removed init_slip_file and read_slip_file which were similarly removed from SRFConfig in earlier commits.

"hyb_corlen_dep_range=1.5",
"hyb_corlen_fac=2.0",
"hyb_corlen_flag=0",
"hyb_corlen_kmodel=schemas.KModel.SUZUKI",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deserialise this like so

        elif isinstance(value, Enum):
            return value.value

in realisation-to-srf

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added elif isinstance(value, Enum): serialised_value = str(value.value) to _build_genslip_command in commit 5401095. Enum values now serialize to their integer values (e.g., kmodel=2, hyb_corlen_kmodel=5).

"tsfac_slope": -0.5,
"circular_average": False,
"kmodel": 2.0,
"kord": 4.0,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be an integer, as discussed the test is not smart enough to know this and I will update later. But for now, change this to

Suggested change
"kord": 4.0,
"kord": 4,

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in commit 5401095 - "kmodel": 2 (int, from IntEnum serialization).

Co-authored-by: lispandfound <12835929+lispandfound@users.noreply.github.com>
@lispandfound lispandfound marked this pull request as ready for review March 5, 2026 20:59
Copilot AI review requested due to automatic review settings March 5, 2026 20:59
Copy link
Contributor

@lispandfound lispandfound left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am happy to merge this once ruff is happy, the tests pass and Cesar/Felipe has had a chance to once over all the defaults and check they are reasonable or match the genslip defaults.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR expands the SRF/genslip configuration surface area so the workflow can drive (nearly) the full genslip v5.6.2 parameter set from realisation configs, with defaults aligned to genslip’s source defaults.

Changes:

  • Added many missing genslip SRF parameters (with defaults) under srf: in the root defaults YAML, and added rvfrac_slip_sig to rupture_velocity.
  • Extended SRF_SCHEMA with validators for the new SRF fields and introduced KModel as an IntEnum.
  • Extended SRFConfig/RuptureVelocity and updated genslip command building to correctly serialise Enum values; updated tests accordingly.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
workflow/scripts/realisation_to_srf.py Serialises Enum/IntEnum SRFConfig values into genslip CLI args; adds rvfrac_slip_sig handling.
workflow/schemas.py Adds KModel enum and expands SRF/RV schema with validators for many new genslip fields.
workflow/realisations.py Extends SRFConfig and RuptureVelocity dataclasses with typed fields for the new parameters.
workflow/default_parameters/root/defaults.yaml Adds the expanded SRF defaults and rvfrac_slip_sig default.
tests/test_realisation_to_srf.py Updates genslip command expectations and config construction to include new fields.
tests/test_realisation.py Updates SRF config example expectations to include the new fields/types.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Literal(
"rvfrac_slip_sig",
description="Rupture velocity fraction slip sigma (null = disabled)."): Or(
NUMBER, None
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rvfrac_slip_sig is a sigma, but the schema allows any NUMBER (including negatives) when not null. Since the sentinel disable value is represented as null/None, it would be safer to validate the numeric case as non-negative (e.g., Or(And(NUMBER, _is_non_negative), None)) to prevent passing invalid negative sigmas through to genslip.

Suggested change
NUMBER, None
And(NUMBER, _is_non_negative), None

Copilot uses AI. Check for mistakes.
Comment on lines +446 to +447
stype: str | None
"""Slip time function type for genslip (None = use genslip default)."""
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stype is annotated as str | None, but the schema validates it with Use(Stype), which will produce a schemas.Stype (a StrEnum). For consistency (and clearer typing for callers), consider changing the field type to schemas.Stype | None (and updating the docstring accordingly).

Suggested change
stype: str | None
"""Slip time function type for genslip (None = use genslip default)."""
stype: schemas.Stype | None
"""Slip time function type for genslip as a schemas.Stype (None = use genslip default)."""

Copilot uses AI. Check for mistakes.
hyb_corlen_flag: bool
"""Enable hybrid correlation length model."""
hyb_corlen_kmodel: schemas.KModel
"""Hybrid correlation length k-model index. Stored as float for schema compatibility."""
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hyb_corlen_kmodel docstring says it's "Stored as float for schema compatibility", but the field is now typed as schemas.KModel. Updating the docstring to reflect the enum (and/or the schema coercion) would avoid confusion for future readers.

Suggested change
"""Hybrid correlation length k-model index. Stored as float for schema compatibility."""
"""Hybrid correlation length k-model (schemas.KModel), parsed/coerced from the schema value."""

Copilot uses AI. Check for mistakes.
Literal(
"hyb_corlen_kmodel",
description="Hybrid correlation length k-model index.",
): And(NUMBER, _is_positive),
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hyb_corlen_kmodel is typed as KModel in SRFConfig, but the schema currently validates it as And(NUMBER, _is_positive). This both (a) rejects the valid KModel.INPUT_CORNERS = -1 value and (b) allows non-integer floats. Consider validating/coercing with Use(KModel) (or an explicit membership check against KModel) so YAML integers are converted to the enum and invalid numeric values are rejected.

Suggested change
): And(NUMBER, _is_positive),
): Use(KModel),

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add remaining Genslip parameters into the codebase

4 participants